import { createRouter, createWebHistory } from "vue-router";
// 1. 配置路由
const routes= [
  {
    path: "/index",
    name:"index",
    component: () => import("../components/index.vue"),
    children:[
      {
        path: "/center",
        name: "center",
        meta:{
          title:'center'
        },
        component: () => import("../components/centers/center.vue")
      },
      {
        path: "/",
        name: "main",
        meta:{
          title:'main'
        },
        component: () => import("../components/Main.vue")
      },
      {
        path: "/aidApply",
        name: "aidApply",
        meta:{
          title:'aidApply'
        },
        component: () => import("../components/operation/aidApply.vue")
      },
      {
        path: "/myAid",
        name: "myAid",
        meta:{
          title:'myAid'
        },
        component: () => import("../components/operation/myAid.vue")
      },
      {
        path: "/myLawyer",
        name: "myLawyer",
        meta:{
          title:'myLawyer'
        },
        component: () => import("../components/operation/myLawyer.vue")
      },
      {
        path: "/myWrit",
        name: "myWrit",
        meta:{
          title:'myWrit'
        },
        component: () => import("../components/operation/myWrit.vue")
      },
      {
        path: "/lawyerFind",
        name: "lawyerFind",
        meta:{
          title:'lawyerFind'
        },
        component: () => import("../components/operation/lawyerFind.vue")
      },
      {
        path: "/lawyerApply",
        name: "lawyerApply",
        meta:{
          title:'lawyerApply'
        },
        component: () => import("../components/operation/lawyerApply.vue")
      },
      {
        path: "/writApply",
        name: "writApply",
        meta:{
          title:'writApply'
        },
        component: () => import("../components/operation/writApply.vue")
      },
      {
        path: "/pageDetail",
        name: "pageDetail",
        meta:{
          title:'pageDetail'
        },
        component: () => import("../components/operation/pageDetail.vue")
      },
    ]
  },
  {
    path: "/login",
    name:"login",
    component: () => import("../components/Login.vue"),
  },
  {
    path: "/adminIndex",
    name:"adminIndex",
    component:()=>import("../components/admin/adminIndex.vue"),
    children: [
      {
        path: "/adminUserManager",
        name: "adminUserManager",
        meta:{
          title:'adminUserManager'
        },
        component: () => import("../components/admin/adminUserManager.vue")
      },
      {
        path: "/adminLawyerManager",
        name: "adminLawyerManager",
        meta:{
          title:'adminLawyerManager'
        },
        component: () => import("../components/admin/adminLawyerManager.vue")
      },
      {
        path: "/adminMain",
        name: "adminMain",
        meta:{
          title:'adminMain'
        },
        component: () => import("../components/admin/adminMain.vue")
      },
      {
        path: "/adminLawCaseManage",
        name: "adminLawCaseManage",
        meta:{
          title:'adminLawCaseManage'
        },
        component: () => import("../components/admin/adminLawCaseManage.vue")
      },
      {
        path: "/adminNews",
        name: "adminNews",
        meta:{
          title:'adminNews'
        },
        component: () => import("../components/admin/adminNews.vue")
      },
      {
        path: "/adminImg",
        name: "adminImg",
        meta:{
          title:'adminImg'
        },
        component: () => import("../components/admin/adminImg.vue")
      }
      ,
      {
        path: "/adminWritManage",
        name: "adminWritManage",
        meta:{
          title:'adminWritManage'
        },
        component: () => import("../components/admin/adminWritManage.vue")
      }
      ,
      {
        path: "/adminCenter",
        name: "adminCenter",
        meta:{
          title:'adminCenter'
        },
        component: () => import("../components/admin/adminCenter.vue")
      }
    ]
  },
  {
    path: "/lawyerIndex",
    name:"lawyerIndex",
    component:()=>import("../components/lawyer/lawyerIndex.vue"),
    children: [
      {
        path: "/aidWork",
        name: "aidWork",
        meta:{
          title:'aidWork'
        },
        component: () => import("../components/lawyer/aidWork.vue")
      },
      {
        path: "/lawyerCenter",
        name: "lawyerCenter",
        meta:{
          title:'lawyerCenter'
        },
        component: () => import("../components/lawyer/lawyerCenter.vue")
      },
      {
        path: "/myApply",
        name: "myApply",
        meta:{
          title:'myApply'
        },
        component: () => import("../components/lawyer/myApply.vue")
      },
      {
        path: "/lawyerMain",
        name: "lawyerMain",
        meta:{
          title:'lawyerMain'
        },
        component: () => import("../components/lawyer/lawyerMain.vue")
      }
    ]
  }

];




// 2.返回一个 router 实列，为函数，配置 history 模式
const router = createRouter({
  history: createWebHistory(),
  routes,
});

// router.beforeEach((to, from, next) => {
//   console.log("beforeEach to:", to);
//   console.log("beforeEach from", from);
//   if (to.path !== "/" && JSON.parse(sessionStorage.getItem("isLogin")) === false) {
//     alert("请先登录");
//     next("/");
//   }
//   next();
// });

// 3.导出路由   去 main.ts 注册 router.ts
export default router